'use strict';
const dayjs = require('dayjs');
module.exports = app => {
    const { STRING, INTEGER, DATE,DECIMAL } = app.Sequelize;
    const Model =  app.model.define(
        'coupon',
        {
            id: {type: INTEGER, primaryKey: true, autoIncrement: true},
            name: STRING(255),
            coupon_no: STRING(255),
            type: INTEGER(11),
            value: DECIMAL(10, 2),
            mini_value: DECIMAL(10, 2),
            status: INTEGER(11),
            start_time: {
                type: app.Sequelize.DATE,
                allowNull: false,
                get() {
                    return dayjs(this.getDataValue('start_time')).format('YYYY-MM-DD');
                },
            },
            end_time: {
                type: app.Sequelize.DATE,
                allowNull: false,
                get() {
                    return dayjs(this.getDataValue('end_time')).format('YYYY-MM-DD');
                },
            },
            create_time: {
                type: app.Sequelize.DATE,
                allowNull: false,
                get() {
                    return dayjs(this.getDataValue('create_time')).format('YYYY-MM-DD HH:mm:ss');
                },
            },
            updated_time: {
                type: app.Sequelize.DATE,
                allowNull: false,
                get() {
                    return dayjs(this.getDataValue('updated_time')).format('YYYY-MM-DD HH:mm:ss');
                },
            }
        },
        {
            tableName: 'coupon',
            timestamps: true, // 启用时间戳(createdAt, updatedAt)
            updatedAt: 'updated_time', // 不想要 updatedAt
            createdAt: 'create_time', // 想要  createdAt 但是希望名称叫做 created_at
        }
    );

    return Model
};



